package com.iob.coin.config;

import com.iob.coin.interceptor.AuthenticationInterceptor;
import com.iob.coin.interceptor.CORSInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: GuoXinyuan
 * @Date: 2021/5/6
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CORSInterceptor());
        registry.addInterceptor(new AuthenticationInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/identify/login")
                .excludePathPatterns("/identify/register")
                .excludePathPatterns("/error")
                .excludePathPatterns("/kgqa/**")
                .excludePathPatterns("/test/**");
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedHeaders("*")
//                .allowedMethods("GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH")
//                .allowCredentials(true)
//                .maxAge(3600)
//                .allowedOriginPatterns("http://localhost:8000");
//    }


}
